﻿package org.openChart.sprite 
{
	import flash.display.Sprite;
	import org.openChart.display.DisplayGroup;
	import org.openChart.display.DisplayGroupSet;
	import org.openChart.sprite.groups.GroupSprite;
	import org.openChart.sprite.groups.GroupFactory;
	import org.openChart.sprite.Command;
	import flash.geom.Point;
	
	/**
	 * ...
	 * @author Chongyuan
	 */
	public class GroupSetSprite extends ContainerSprite
	{
		protected var toolTip:ToolTipSprite;
		
		public function GroupSetSprite( displayGroupSet:DisplayGroupSet, commandHandler:CommandHandler ) 
		{
			super(displayGroupSet, commandHandler);
			toolTip = new ToolTipSprite(null, this);
			for (var i:uint = 0; i < displayGroupSet.length; i++)
			{
				var displayGroup:DisplayGroup = displayGroupSet.getAt(i);
				addGroup(displayGroup);
			}
			toolTip.visible = false;
			addChild(toolTip);
		}
		
		public function addGroup( displayGroup:DisplayGroup):void
		{
			var groupSprite:GroupSprite = GroupFactory.create(displayGroup, this);
			this.addChild(groupSprite);
		}
		
		public override function processMouseCommand(command:uint, traget:BaseSprite, position:Point, object:Object):void
		{
			if (command == Command.TOOLTIP_HIDE)
			{
				toolTip.visible = false;
			}
			else if (command == Command.TOOLTIP_SHOW)
			{
				toolTip.text = "The value is " + object.value;
				toolTip.position = position;
				toolTip.repaint();
				toolTip.visible = true;
			}
		}
	}
	
}